package com.edu.atams.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.edu.atams.entity.Student;
import com.edu.atams.entity.SysUser;
import com.edu.atams.mapper.SysUserMapper;
import com.edu.atams.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author czj666
 * @since 2021-10-09
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public Integer setUserByStudent(Student student) {
        SysUser sysUser = new SysUser();
        sysUser.setUsername(student.getSchoolno());
        String password = bCryptPasswordEncoder.encode("123456");
        sysUser.setPassword(password);
        sysUser.setRoleType(1);
        this.save(sysUser);
        return sysUser.getId();
    }

    @Override
    public SysUser getByUsername(String username) {
        //查找老师的账号
        return getOne(new QueryWrapper<SysUser>().eq("username", username).eq("role_type",2));
    }

}
